<?php
session_start();
//ini_set('display_errors',1);
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin=new admin();
$admin->canView($_SERVER['PHP_SELF']);
$groups=$admin->getGroups();

ob_start("sanitize_output"); 
?>
<div class="oneem">
<div class="qt-tab-wrapper" style="height:90%;">
<ul class="qt">
    <li><a href="#st1-pages" id="st1" class="qta">Groups</a></li>
    <li><a href="#st2-pages" id="st2" class="qta">Edit</a></li>
</ul>
<div id="st1-pages" class="qt-content-container" style="display:none;">
<div style="float:right;width:48%;">
<h2 class="form-heading">Current Groups</h2>
	<table width="99%" class="headed-table">
	<thead>
    <tr valign="top">
    <td width="1%" class="hleft"></td>
    <td width="94%"><h6>&nbsp;Group Name</h6></td>
	<td width="5%" class="hright"></td>
</tr>
</thead>
<tbody>
	<?php 
	$i=0;
	foreach($groups as $row) {
		$bg=($i%2) ? ' odd' : '';	
		echo('<tr>');
		echo('<td class="left'.$bg.'"><a href="/admin/resources/php/requests/actions/delete-group.php?gid='.(string)$row['_id'].'" class="delete-group tip" title="Delete this group"><img src="/admin/resources/images/cancel.png" /></a></td>');
		echo('<td class="'.trim($bg).'">'.$row['label'].'</td>');
		echo('<td class="right'.$bg.'" style="text-align:right;"><a href="/admin/resources/php/requests/forms/edit-group.php?group='.$row['label'].'&gid='.(string)$row['_id'].'" class="group-edit"><img src="/admin/resources/images/b_edit.png" /></a></td>');
		echo('</tr>');
		$i++;
	}
	?>
</tbody>
</table>
</div>

<div style="float:left;width:50%;">
<h2 class="form-heading">Add a new Group</h2>
<form class="inline" action="/admin/resources/php/requests/actions/add-group.php">
<input type="hidden" class="settings" value='{"buttonWaitingValue":"Adding","updateNode":"#response"}' />	
<label>Group Name:</label><br />
<input type="text" class="comment-field req" name="group_name" id="group_name" style="width:200px" />     
<p class="hint">Name of the new group <strong>Required</strong></p>

<p><input type="submit" class="button" value="Add group" /></p>
</form>
</div>




</div>
<div id="st2-pages" class="qt-content-container" style="display:none;">
	<h2 class="form-heading">Please choose a group to edit first</h2>
</div>
</div>
</div>
<script>
$("#st1").click();
</script>